package com.windowes.weichang.controller.manage;

import com.windowes.weichang.common.ServerResponse;
import com.windowes.weichang.service.HistoryCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Objects;

/***
 *
 * @author: yangqing
 * @email: qing.yang@bangdao-tech.com
 * @createTime: 2018/6/16 下午7:05
 * @description:
 *
 **/
@Api(description = "历史订单相关API")
@RestController
@RequestMapping("history")
@Slf4j
public class HistoryController {


    @Autowired
    HistoryCustomerService historyCustomerService;

    @ApiOperation(value = "导入历史订单", notes = "excel文件导入")
    @PostMapping("/importHistory")
    public ServerResponse singleFileUpload(MultipartFile file) {
        if (Objects.isNull(file) || file.isEmpty()) {
            return ServerResponse.createByErrorMessage("文件为空，请重新上传");
        }
        return historyCustomerService.importHistory(file);
    }

    @ApiOperation(value = "历史订单列表", notes = "excel文件导入")
    @GetMapping("customers")
    public ServerResponse customers(String keyword,  @RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                    @RequestParam(value = "pageSize", defaultValue = "15") int pageSize) {
        return historyCustomerService.users(keyword,pageNo, pageSize);
    }


}